Intruduction to MelGeneralizedCepstrums.jl

This notebook shows the basic usage of MelGeneralizedCepstrums.jl.

Preparation

  • Configure visualization settings (using PyPlot in this notebook)
  • Loading an audio file (using WAV package)

In [1]:
using PyCall
matplotlib = pyimport("matplotlib")
PyDict(matplotlib["rcParams"])["figure.figsize"] = (12, 5)
using PyPlot


WARNING: using PyPlot.matplotlib in module Main conflicts with an existing identifier.

In [2]:
import SPTK
using WAV
using DSP
using MelGeneralizedCepstrums

In [3]:
x, fs = wavread(joinpath(Pkg.dir("SPTK"), "examples", "test16k.wav"), format="native")
x = convert(Vector{Float64}, vec(x))

# Visualize the speech signal in time-domain
plot(1:endof(x), x, label="a speech signal")
xlim(1, endof(x))
xlabel("sample")
legend()


Out[3]:
PyObject <matplotlib.legend.Legend object at 0x7f6e03c7a190>

Windowing


In [4]:
# Pick a short segment
pos = 3000
fftlen = 1024

# Note that mel-generalized cepstrum analysis assumes power-normalized window so that Σₙ w(n)² = 1
win = DSP.blackman(fftlen) ./ sqrt(sumabs2(DSP.blackman(fftlen))) # or you can write simply `SPTK.blackman(fftlen)`
@assert isapprox(sumabs2(win), 1.0)

xw = x[pos+1:pos+fftlen] .* win

plot(1:endof(xw), xw, linewidth="2", label="a windowed speech signal")
xlim(1, endof(xw))
xlabel("sample")
legend()


Out[4]:
PyObject <matplotlib.legend.Legend object at 0x7f6e03ae77d0>

Mel-generalized cepstrum analysis


In [5]:
# Plotting utility for visualizing spectral envelope estimate
function pplot(sp, envelope; title="envelope")
    plot(sp, "b-", linewidth="2", label="Original log spectrum 20log|X(ω)|")
    plot(20/log(10)*(envelope), "r-", linewidth="3", label=title)
    xlim(1, length(sp))
    xlabel("frequency bin")
    ylabel("log amplitude")
    legend()
end


Out[5]:
pplot (generic function with 1 method)

In [6]:
# Compute spectrum 20log|X(ω)| for a windowed signal
sp = 20log10(abs(rfft(xw)));

In [7]:
# Linear Cepstrum
c = estimate(LinearCepstrum(20), xw)
pplot(sp, real(mgc2sp(c, fftlen)), title="Linear frequency cepstrum based envelope")


Out[7]:
PyObject <matplotlib.legend.Legend object at 0x7f6e02f49a10>

In [8]:
# Mel-Cepstrum
mc = estimate(MelCepstrum(20, 0.41), xw)
pplot(sp, real(mgc2sp(mc, fftlen)), title="Mel-cepstrum based envelope")


Out[8]:
PyObject <matplotlib.legend.Legend object at 0x7f6e02e930d0>

In [9]:
# LPC Cepstrum 
mgc = estimate(AllPoleCepstrum(20), xw)
pplot(sp, real(mgc2sp(mgc, fftlen)), title="LPC cepstrum based envelope")


Out[9]:
PyObject <matplotlib.legend.Legend object at 0x7f6e02dcfd10>

In [10]:
# Warped LPC
mgc = estimate(MelGeneralizedCepstrum(20, 0.41, -1.0), xw)
pplot(sp, real(mgc2sp(mgc, fftlen)), title="Warped LPC based envelope")


Out[10]:
PyObject <matplotlib.legend.Legend object at 0x7f6e02d19ad0>

In [11]:
# Generalized Cepstrum
mgc = estimate(GeneralizedCepstrum(20, -0.35), xw)
pplot(sp, real(mgc2sp(mgc, fftlen)), title="Generalized cepstrum based envelope")


Out[11]:
PyObject <matplotlib.legend.Legend object at 0x7f6e02a3b9d0>

In [12]:
# Mel-Generalized Cepstrum
mgc = estimate(MelGeneralizedCepstrum(20, 0.41, -0.35), xw)
pplot(sp, real(mgc2sp(mgc, fftlen)), title="Mel-generalized cepstrum based envelope")


Out[12]:
PyObject <matplotlib.legend.Legend object at 0x7f6e029848d0>